package cn.edu.hziee;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "AddServlet" ,urlPatterns = "/AddServlet")
public class AddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String number = request.getParameter("Number");
        String name = request.getParameter("Name");
        String chinese = request.getParameter("Chinese");
        String math = request.getParameter("Math");
        String english = request.getParameter("English");
        HttpSession session = request.getSession();
        Grade grade = new Grade();
        List<Grade> card = (List) session.getAttribute("card");
        if (card == null) {
            card = new ArrayList<Grade>();
            grade.setId(0);
        }else {
            grade.setId(card.size());
        }
        grade.setNumber(number);
        grade.setName(name);
        grade.setChinese(chinese);
        grade.setMath(math);
        grade.setEnglish(english);

        card.add(grade);
        session.setAttribute("card",card);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
